///<reference path="../../../core/model/CommonDto.ts"/>
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, FormControl, Validators } from '@angular/forms';
import { FormValidatorService } from "../../../core/service/form-validator.service";
import { HttpService } from "../../../core/service/http.service";
import { Register } from "../../../core/model/Register";
import { HttpRes } from "../../../core/model/HttpRes";
import { Router, ActivatedRoute } from "@angular/router";
import { AuthService } from "../../../core/service/auth.service";
import { NzMessageService, NzModalRef, NzModalService, UploadFile } from 'ng-zorro-antd';
import { Login } from "../../../core/model/Login";
import { ClassInfoOutput } from "../../../core/model/ClassInfoDto";
import { PagerSearchInput, PagedResultDto, ElementViewType } from "../../../core/model/CommonDto";


@Component({
  selector: 'app-my-drill-report',
  templateUrl: './my-drill-report.component.html',
  styleUrls: ['../../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component.scss', './my-drill-report.component.scss']
})
export class StudentDrillReportComponent implements OnInit {
  drillId;
  hasReport = false;
  confirmModal: NzModalRef;
  signForm: FormGroup;
  uploading = false;
  fileList: UploadFile[] = [];

  constructor(public fb: FormBuilder,
    public FormValidator: FormValidatorService,
    private modal: NzModalService,
    public http: HttpService,
    public router: Router,
    public route: ActivatedRoute,
    public Auth: AuthService) {
    this.newMethod();
  }

  private newMethod() {
    this.drillId = this.route.snapshot.params['id'];
    this.GetReport();
  }

  ngOnInit() {
  }
  async GetReport() {
    const req = await this.http.get<any>(`DrillRecord/GetReport?drillRecordId=${this.drillId}`);
    if (!req) {
      this.hasReport = true;
    }
  }
  // 上传演练报告
  async toUploadReport(value: any) {
    this.confirmModal = this.modal.confirm({
      nzTitle: '上传演练报告?',
      nzContent: '点击确定后，此演练的信息将被删除。',
      nzOnOk: () => {

      },
      nzOnCancel: () => {

      }
    });
  }
  beforeUpload = (file: UploadFile): boolean => {
    this.fileList.push(file);
    return false;
  }

  async handleUpload() {
    const formData = new FormData();
    // tslint:disable-next-line:no-any
    formData.append('drillRecordId', this.drillId);
    this.fileList.forEach((file: any) => {
      formData.append('fileinput', file);
    });
    this.uploading = true;
    // You can use any AJAX library you like
    // const startpar = { Id: this.startDrillId };
    const req = await this.http.post<any>('DrillRecord/UploadReport', formData);
    this.router.navigate(['app/mydrill/index']);
  }
  backpage() {
    window.history.go(-1);
  }
}

